package utils

import (
	"fmt"
	"math/rand"
	"strings"
	"time"
)

func RandomStr(width int) string {
	var numeric = [10]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	r := len(numeric)
	rand.Seed(time.Now().UnixNano())
	var sb strings.Builder
	for i := 0; i < width; i++ {
		_, _ = fmt.Fprintf(&sb, "%d", numeric[rand.Intn(r)])
	}
	return sb.String()
}

func HideMiddleStr(str string, startLen int, endLen int, replaceLetter ...string) string {
	rl := "*"
	if len(replaceLetter) > 0 {
		rl = replaceLetter[0]
	}
	strlen := len(str)
	mLen := strlen - startLen - endLen
	if mLen > 0 {
		return str[0:startLen] + strings.Repeat(rl, mLen) + str[strlen-endLen:]
	}
	return str
}
